<?php
/**
 * Created by PhpStorm.
 * User: 丶晓
 * Date: 2017/9/23
 * Time: 9:51
 */

namespace app\api\model;


use think\Db;
use think\Model;

class MiniappsModel extends Model
{

    // 查
    public function selectInfo($type, $data = [])
    {
        if (empty($type)) {
            return false;
        }
        switch ($type) {
            case 'templateInfo':
                if (Db::table('wyz_template')->where('template_id', $data['template_id'])->count() != 1) {
                    return false;
                }
                $RES = Db::table('wyz_template')->where('template_id', $data['template_id'])->select();
                return isset($RES[0]) ? $RES[0] : false;
                break;
        }
        return false;
    }

    // 增
    public function addInfo($type, $data = [])
    {
        if (empty($type) or empty($data)) {
            return false;
        }
        switch ($type) {
            case 'zeroPriceTemplate':
                // 价格为0模板生成购买成功订单
                if (!isset($data['uid']) or !isset($data['template_id'])) {
                    return false;
                }
                if (Db::table('wyz_template_order')->where('uid', $data['uid'])
                    ->where('template_id', $data['template_id'])->where('is_pay', 1)->count()) {
                    return false;
                }
                if (Db::table('wyz_template_order')->insert([
                    'uid' => $data['uid'],
                    'template_id' => $data['template_id'],
                    'is_pay' => 1,
                    'ali_pay_id' => 'free',
                    'wechat_pay_id' => 'free',
                ])) {
                    return true;
                }
                break;
        }

        return false;
    }

// 改
    public function changeInfo($type, $data = [])
    {
        if (empty($type) or empty($data)) {
            return false;
        }
        switch ($type) {
            case '':
                break;
        }
        return false;
    }

// 删
    public function deleteInfo($type, $data = [])
    {
        if (empty($type)) {
            return false;
        }
        return false;

    }
}